package com.ys.nms.module.business.service.otheroid;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import com.ys.nms.module.business.controller.admin.otheroid.vo.*;
import com.ys.nms.module.business.dal.dataobject.otheroid.OtherOidDO;
import com.ys.nms.framework.common.pojo.PageResult;
import com.ys.nms.framework.common.pojo.PageParam;
import com.ys.nms.framework.common.util.object.BeanUtils;

import com.ys.nms.module.business.dal.mysql.otheroid.OtherOidMapper;

import static com.ys.nms.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.convertList;
import static com.ys.nms.framework.common.util.collection.CollectionUtils.diffList;
import static com.ys.nms.module.business.enums.ErrorCodeConstants.*;

/**
 * 补充其它OID Service 实现类
 *
 * @author zzy
 */
@Service
@Validated
public class OtherOidServiceImpl implements OtherOidService {

    @Resource
    private OtherOidMapper otherOidMapper;

    @Override
    public Long createOtherOid(OtherOidSaveReqVO createReqVO) {
        // 插入
        OtherOidDO otherOid = BeanUtils.toBean(createReqVO, OtherOidDO.class);
        otherOidMapper.insert(otherOid);

        // 返回
        return otherOid.getId();
    }

    @Override
    public void updateOtherOid(OtherOidSaveReqVO updateReqVO) {
        // 校验存在
        validateOtherOidExists(updateReqVO.getId());
        // 更新
        OtherOidDO updateObj = BeanUtils.toBean(updateReqVO, OtherOidDO.class);
        otherOidMapper.updateById(updateObj);
    }

    @Override
    public void deleteOtherOid(Long id) {
        // 校验存在
        validateOtherOidExists(id);
        // 删除
        otherOidMapper.deleteById(id);
    }

    @Override
        public void deleteOtherOidListByIds(List<Long> ids) {
        // 删除
        otherOidMapper.deleteByIds(ids);
        }


    private void validateOtherOidExists(Long id) {
        if (otherOidMapper.selectById(id) == null) {
            throw exception(OTHER_OID_NOT_EXISTS);
        }
    }

    @Override
    public OtherOidDO getOtherOid(Long id) {
        return otherOidMapper.selectById(id);
    }

    @Override
    public PageResult<OtherOidDO> getOtherOidPage(OtherOidPageReqVO pageReqVO) {
        return otherOidMapper.selectPage(pageReqVO);
    }

}